import akshare as ak
import pandas as pd

class checkStock(object):
    # 将每股收益（esp）>1，市净率0<PB<1
    def getyjbb(self):
        stock_em_yjbb_df = ak.stock_yjbb_em()
        # 将每股收益（esp）>1，市净率0<PB<1
       # stock_em_yjbb_df = stock_em_yjbb_df[(stock_em_yjbb_df['每股收益'] > 1)]
        #stock_em_yjbb_df = stock_em_yjbb_df.set_index('股票代码')
        #print(stock_em_yjbb_df)
        return stock_em_yjbb_df

    def getnow(self):

        # 获取股票日 K 线数据
        # df = ef.stock.get_quote_history(stock_code)
        # 将df0按code进行排序
        # df = df.sort_index(axis=0, ascending=True)
        # 将 涨跌幅（changepercent)<4% 和 0.8%<换手率(turnoverratio)<3% 的保留下来
        # df = df[(df['涨跌幅']<4) & (0.8<df['换手率'])&(df['换手率']<3)]
        # print(df)
        # print(len(df))

        stock_zh_a_spot_em_df = ak.stock_zh_a_spot_em()  # 4908
        # 将每股收益（esp）>1，市净率0<PB<1
        #stock_zh_a_spot_em_df = stock_zh_a_spot_em_df[(0 < stock_zh_a_spot_em_df['市净率']) & (stock_zh_a_spot_em_df['市净率'] < 1) & (stock_zh_a_spot_em_df['涨跌幅']<4) & (0.8<stock_zh_a_spot_em_df['换手率'])&(stock_zh_a_spot_em_df['换手率']<3)]
        #stock_zh_a_spot_em_df = stock_zh_a_spot_em_df.set_index('代码')
        #print(stock_zh_a_spot_em_df)
        return stock_zh_a_spot_em_df

if __name__ == '__main__':
    demo = checkStock()
    df0 = demo.getyjbb() #获取业绩报表
    print(df0)
    df1 = demo.getnow()
    print(df1)
    """
    for item in df0['股票代码']:
        for item1 in df1['代码']:
            if item == item1:
                #print(item)
                # 将df0和df1横向拼接起来，赋给df
                df = pd.merge(df0, df1, how='inner')
                print(df)
    """